<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>取得某索引的颜色</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.imagecolorsforindex" class="refentry">
  <div class="refnamediv">
   <h1 class="refname">imagecolorsforindex</h1>
   <p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">imagecolorsforindex</span> &mdash; <span class="dc-title">取得某索引的颜色</span></p>

  </div>
  <div class="refsect1 unknown-unknown-seealsq" id="refsect1-function.imagecolorsforindex-unknown-unknown-seealsq">
   <h3 class="title">说明</h3>
   <div class="methodsynopsis dc-description">
    <span class="methodname"><strong>imagecolorsforindex</strong></span>
     ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$image</code></span>
    , <span class="methodparam"><span class="type">int</span> <code class="parameter">$index</code></span>
    ) : <span class="type">array</span></div>

   <p class="para rdfs-comment">
    本函数返回一个具有 red，green，blue 和 alpha
    的键名的关联数组，包含了指定颜色索引的相应的值。
   </p>
   <p class="para">
    <div class="example" id="example-3670">
     <p><strong>Example #1 <span class="function"><strong>imagecolorsforindex()</strong></span> 例子</strong></p>
     <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">//&nbsp;打开一幅图像<br /></span><span style="color: #0000BB">$im&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imagecreatefrompng</span><span style="color: #007700">(</span><span style="color: #DD0000">'nexen.png'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;取得一点的颜色<br /></span><span style="color: #0000BB">$start_x&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">40</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$start_y&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">50</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$color_index&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imagecolorat</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$start_x</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$start_y</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;使其可读<br /></span><span style="color: #0000BB">$color_tran&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imagecolorsforindex</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$color_index</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;显示该颜色的值<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">'&lt;pre&gt;'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$color_tran</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">'&lt;/pre&gt;'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
     </div>

     <div class="example-contents"><p>
      本例将输出：
     </p></div>
     <div class="example-contents screen">
<div class="cdata"><pre>
Array
(
    [red] =&gt; 226
    [green] =&gt; 222
    [blue] =&gt; 252
    [alpha] =&gt; 0
)
</pre></div>
     </div>
    </div>
   </p>
   <p class="para">
    参见 <span class="function"><a href="imagecolorat.html" class="function">imagecolorat()</a></span> 和
    <span class="function"><a href="imagecolorexact.html" class="function">imagecolorexact()</a></span>。
   </p>
  </div>

 </div></div></div></body></html>